package SwingView;

import javax.swing.JPanel;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JTextField;
import javax.swing.JButton;

public class CmsWeightSelector extends JPanel{
	private Double weight;
	private JTextField jtfWeight;

	public CmsWeightSelector(){
		weight = 0.0;
		
		FlowLayout flowLayout = (FlowLayout) getLayout();
		flowLayout.setVgap(0);
		flowLayout.setAlignment(FlowLayout.LEFT);
		this.setOpaque(false);
		
		jtfWeight = new JTextField();
		jtfWeight.setEditable(false);
		add(jtfWeight);
		jtfWeight.setColumns(5);
		
		JButton btnAdjust = new JButton("Adjust");
		btnAdjust.setOpaque(false);
		btnAdjust.setBorder(BorderFactory.createEmptyBorder());
		btnAdjust.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		btnAdjust.setForeground(Color.BLUE);
		add(btnAdjust);
	
		btnAdjust.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				weight = CmsWeightInputDialog.showInputDialog(weight);
				jtfWeight.setText("" + weight+ "%");
			}
			
		});
	}
	
	public void reset(){
		weight = 0.0;
		jtfWeight.setText("" + weight+ "%");
	}
	
	public double getWeight(){
		return weight;
	}
	
	public void setWeight(double weight){
		this.weight = weight;
		jtfWeight.setText("" + weight+ "%");
	}
}
